'
'   XC Engine. A simple engine to drive the Internet Explorer web browser
'   Copyright (C) 2009 Stanislav Hordiyenko
'
'   This program is free software; you can redistribute it and/or modify
'   it under the terms of the GNU General Public License as published by
'   the Free Software Foundation; either version 3 of the License, or
'   (at your option) any later version.
'
'   This program is distributed in the hope that it will be useful,
'   but WITHOUT ANY WARRANTY; without even the implied warranty of
'   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'   GNU General Public License for more details.
'
'   You should have received a copy of the GNU General Public License
'   along with this program; if not, see http://www.gnu.org/licenses
'   or write to the Free Software Foundation,Inc., 51 Franklin Street,
'   Fifth Floor, Boston, MA 02110-1301 USA
'

Class IEManager
	Public Function OpenBrowser()
		Set objIE = WScript.CreateObject("InternetExplorer.Application")
		Set objIEBrowser = New IE
		
		objIE.Visible = True
		objIE.Navigate "about:blank"
		
		objIEBrowser.WrapBrowser(objIE)
		
		Set OpenBrowser = objIEBrowser
	End Function
	
	Public Sub CloseAll()
		Set objWmi = GetObject("winmgmts:{impersonationLevel=impersonate}")
		Set objWin32Processes = objWmi.InstancesOf("Win32_process")

		For Each objWin32Process In objWin32Processes
			If InStr(1, LCase(objWin32Process.Name), LCase("iexplore")) > 0 Then
				objWin32Process.Terminate 0
			End If
		Next
	End Sub

	Public Function Count()
		Set objShellApplication = WScript.CreateObject("Shell.Application")     
		
		If IsObject(objShellApplication) Then
			intIEWindowCount = 0     
			     
			Set objIEWindows = objShellApplication.Windows          

			For Each objIEWindow In objIEWindows
				On Error Resume Next             

				objIEWindowType = ""
				objIEWindowType = TypeName(objIEWindow.Document)
	               
				If UCase(objIEWindowType) = "HTMLDOCUMENT" Then          
					intIEWindowCount = intIEWindowCount + 1
				End If
			Next

			Set objIEWindow = Nothing
		End If     

		Set objShellApplication = Nothing
		
		Count = intIEWindowCount
	End Function
End Class